import 'dart:convert';

import 'package:amway_superapp_creator_plugin/analysis/zhuge_circle.dart';
import 'package:amway_superapp_creator_plugin/analysis/zhuge_identify.dart';
import 'package:amway_superapp_creator_plugin/utils/sp_util.dart';
import 'package:zhugeio/zhugeio.dart';

enum GoodsReCommendaionPageType {
  RecommendPage,

  ///物推荐页
  RecommendAddGoods,

  ///好物推荐页_点击添加商品
  RecommendDelGoods,

  ///好物推荐页_点击删除商品
  SelectedCombinationClickTipDialog,

  ///精选组合列表页_点击删除商品弹窗
  SelectedCombinationClickDelDialog,

  ///精选组合列表页_点击删除商品弹窗
  SelectedCombinationClickSave,

  ///好物推荐页_点击保存
}

class ZhugeGoodsRecommendationAnalysis {
  static String _goodsRecommendtionPageType(
      GoodsReCommendaionPageType goodsReCommendaionPageType) {
    switch (goodsReCommendaionPageType) {
      case GoodsReCommendaionPageType.RecommendPage:
        return "SuperAPP_创玩小站好物推荐页";
        break;
      case GoodsReCommendaionPageType.RecommendAddGoods:
        return "SuperAPP_创玩小站好物推荐页_点击添加商品";
        break;
      case GoodsReCommendaionPageType.RecommendDelGoods:
        return "SuperAPP_创玩小站好物推荐页_点击删除商品";
        break;
      case GoodsReCommendaionPageType.SelectedCombinationClickTipDialog:
        return "SuperAPP_创玩小站精选组合列表页_点击删除商品弹窗";
        break;
      case GoodsReCommendaionPageType.SelectedCombinationClickDelDialog:
        return "SuperAPP_创玩小站精选组合列表页_点击删除商品弹窗";
        break;
      case GoodsReCommendaionPageType.SelectedCombinationClickSave:
        return "SuperAPP_创玩小站好物推荐页_点击保存";
        break;
    }
  }

  ///好物推荐页面加载完成
  ///0 1 2 <空/有商品/待审核>
  static goodsReCommendaionPageLoadFinsh(int state) {
    SpUtil.getData(amwayAccesstypeKey).then((customerType) {
      Zhugeio.track(
          _goodsRecommendtionPageType(
              (GoodsReCommendaionPageType.RecommendPage)),
          {
            "事件类型": "页面浏览",
            "页面类别": "创玩小站",
            "访客类别": customerType, //ABO
            "页面详情": "无",
            "状态": state == 0
                ? "空"
                : state == 1
                    ? "有商品"
                    : "待审核",
          });
    });
  }

  ///好物推荐页_点击添加商品
  static goodsReCommendaionAddGoods(String pageTitle) {
    SpUtil.getData(amwayAccesstypeKey).then((customerType) {
      Zhugeio.track(
          _goodsRecommendtionPageType(
              (GoodsReCommendaionPageType.RecommendAddGoods)),
          {
            "事件类型": "点击事件",
            "行为类型": "点击",
            "访客类别": customerType, //ABO
            "行为对象": "按钮",
            "页面名称": pageTitle,
          });
    });
  }

  ///好物推荐页_点击删除商品
  static goodsReCommendaionDelGoods(String pageTitle, String goodId) {
    SpUtil.getData(amwayAccesstypeKey).then((customerType) {
      Zhugeio.track(
          _goodsRecommendtionPageType(
              (GoodsReCommendaionPageType.RecommendDelGoods)),
          {
            "事件类型": "点击事件",
            "行为类型": "点击",
            "访客类别": customerType, //ABO
            "行为对象": "按钮",
            "页面名称": pageTitle,
            "商品ID": goodId
          });
    });
  }

  ///精选组合列表页_点击删除商品弹窗
  static goodsReCommendaionDelGoodsDialog(String pageTitle, bool isConfrim) {
    SpUtil.getData(amwayAccesstypeKey).then((customerType) {
      Zhugeio.track(
          _goodsRecommendtionPageType(
              (GoodsReCommendaionPageType.SelectedCombinationClickTipDialog)),
          {
            "事件类型": "弹窗点击事件",
            "行为类型": "点击",
            "访客类别": customerType, //ABO
            "行为对象": "按钮",
            "页面名称": pageTitle,
            "弹窗描述": "将退出编辑,是否保存",
            "事件详情": isConfrim ? "保存并退出" : "继续编辑"
          });
    });
  }

  ///精选组合列表页_点击删除商品弹窗
  static goodsReCommendaionDelGoodsDialog1(String pageTitle, bool isConfrim) {
    SpUtil.getData(amwayAccesstypeKey).then((customerType) {
      Zhugeio.track(
          _goodsRecommendtionPageType(
              (GoodsReCommendaionPageType.SelectedCombinationClickDelDialog)),
          {
            "事件类型": "弹窗点击事件",
            "行为类型": "点击",
            "访客类别": customerType, //ABO
            "行为对象": "按钮",
            "页面名称": pageTitle,
            "弹窗描述": "确认删除此好物推荐吗",
            "事件详情": isConfrim ? "确认" : "取消"
          });
    });
  }

  ///SuperAPP_创玩小站好物推荐页_点击保存
  static goodsReCommendaionSaveGoods(String pageTitle, List<String> goodsIds) {
    SpUtil.getData(amwayAccesstypeKey).then((customerType) {
      Zhugeio.track(
          _goodsRecommendtionPageType(
              (GoodsReCommendaionPageType.SelectedCombinationClickSave)),
          {
            "事件类型": "点击事件",
            "行为类型": "点击",
            "访客类别": customerType, //ABO
            "行为对象": "按钮",
            "页面名称": pageTitle,
            "商品ID": goodsIds != null && goodsIds.length > 0
                ? jsonEncode(goodsIds)
                : null,
          });
    });
  }
}
